package com.zzyl.controller.customer;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.VisitDto;
import com.zzyl.entity.visit.Visit;
import com.zzyl.service.ReservationService;
import com.zzyl.utils.ThreadLocalUtil;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
@RequiredArgsConstructor
public class CustomerReservationController {
    private final ReservationService reservationService;;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<?> cancelledCount() {
        return ResponseResult.success(reservationService.cancelledCount());
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<?> countByTime( Long time) {
        System.out.println(time+"time");
        List<TimeCountVo> timeCountVo = reservationService.countByTime(time);
        return ResponseResult.success(timeCountVo);
    }
    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult<?> postCount(@RequestBody Visit visit) {
        System.out.println(visit+"Visit");
        reservationService.postCount(visit);
        return ResponseResult.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    @Validated
    public ResponseResult<?> pageCount(@Min(1) Integer pageNum,@Min(1)  Integer pageSize,@RequestParam(required=false) Integer status) {
        PageBean<ReservationVo> list = reservationService.pageCount(pageNum, pageSize, status);
        System.out.println(list);
        return ResponseResult.success(list);
    }
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult<?> clearCount(@PathVariable Long id) {
        reservationService.clearCount(id);
        return ResponseResult.success();
    }
}
